package com.example.hello.client.AlertBlock;

import com.example.hello.BootstrapAlertBlock;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapAlertBlock.class)
public class BootstrapAlertBlockConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapAlertBlock.class);
    }

    @Override
    public BootstrapAlertBlockState getState() {
        return (BootstrapAlertBlockState) super.getState();
    }

    @Override
    public VBootstrapAlertBlock getWidget() {
        return (VBootstrapAlertBlock) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapAlertBlockState state = getState();

        VBootstrapAlertBlock alert = getWidget();

        alert.setAnimation(state.isAnimation());
        alert.setClose(state.isClose());
        alert.setHeading(state.getHeading());
        alert.setText(state.getText());
        alert.setType(AlertType.valueOf(state.getType()));
    }

}